package cn.edu.xmu.restfuldemo.model;


import  cn.edu.xmu.restfuldemo.model.Orders;

import  cn.edu.xmu.restfuldemo.model.OrderItem;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class OrdersVo {
    private List<OrderItemVo> orderItems;
    private String consignee;
    private Integer regionId;
    private String address;
    private String mobile;
    private String message;
    private Integer couponId;
    private Integer presaleId;
    private Integer grouponId;

    public Orders createOrder(){
        Orders order = new Orders();
        order.setConsignee(consignee);
        order.setRegionId(regionId);
        order.setAddress(address);
        order.setMobile(mobile);
        order.setMessage(message);
        order.setCouponId(couponId);
        order.setPresaleId(presaleId);
        order.setGrouponId(grouponId);
        if(null!=orderItems){
            List<OrderItem> list = new ArrayList<>(orderItems.size());
            for(OrderItemVo orderItemVo: orderItems){
                list.add(orderItemVo.createOrderItem());
            }
            order.setOrderItems(list);
        }
        return order;
    }
}
